Social Icons

twitter google plus linkedin rss feed

Pages

28.1.11

Uploading Machines to Azure VM Role

As all the technology we use at Stratex Systems is from Microsoft it looks simple logic to host our virtual machines in the Azure cloud... Beta!, now I'm scared. There's not too much information available about this at the moment, so I'll try to write about my experience.

The first thing I want to tell to anyone who is trying to test the VM Role is that you need to be accepted in the beta program. There are a lot of web pages including several from Microsoft that say that you'll only need to sing up and that's enough to start working, but it's not true.

If you don't know what's this all about, Azure VM Role is a new system to sell IaaS (Infrastructure as a Service) where you can upload your Hyper-V hard disks after installing all the software you need and they'll bring them to live. After that, they'll charge you for the storage, processor number and the amount of RAM you use (per hour).

Well, to say the truth, I can't talk much more about this topic because I'm still waiting to be accepted in the beta program...



Now I feel like a 15 year old boy, a lot of theory, but very little practice.

No comments:

Post a Comment

3.12.10

Copying ListViewWebparts between sites with their own custom views

In a new example of what I call "Guerrilla Coding" I had a couple of hours to develop a little program to copy hundreds of webpart pages full of ListViewWebparts, each one with its own custom view. I don't know if you feel the same, but I start to tremble every time I have to touch anything related to the ListViewWebpart

The ListViewWebparts create in the parent list a hidden view when we customize their view. This means that if you want to copy the webparts to a new site you'll have to copy the views from the parent list to its destination equivalent, I don't think I'm explaining my point well... I'd better paste the code...

What I do in this code snippet is copying the webparts from every origin file to the destination one giving them a special treatment if they are LisvViewWebpart which is enough for the application I need.

private static void CopyWebParts(SPFile origFile, SPFile destFile)
        {
            SPLimitedWebPartManager origWpm = origFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
            SPLimitedWebPartManager destWpm = destFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

            DeleteWebparts(destWpm);

            foreach (Microsoft.SharePoint.WebPartPages.WebPart webpart in origWpm.WebParts)
            {
                Microsoft.SharePoint.WebPartPages.WebPart newWp;

                if (webpart is ListViewWebPart)
                    newWp = UpdateListViewWebPart(webpart as ListViewWebPart, origFile.GetWeb(), destFile.GetWeb());
                else
                    newWp = webpart;

                destWpm.AddWebPart(newWp, Common.ConvertToString(newWp.ZoneID), newWp.ZoneIndex);
            }

            try
            {
                destFile.Publish("Added Web Parts");
                destFile.Approve("Web Part additions approved");
            }
            catch { }
        }

        private static ListViewWebPart UpdateListViewWebPart(ListViewWebPart webpart, SPWeb origWeb, SPWeb destWeb)
        {
            ListViewWebPart newWebPart = webpart; //yeah I know.

            string oldListName = webpart.ListName;
            string oldViewGuid = webpart.ViewGuid;

            SPList OrigList = origWeb.Lists.GetList(new Guid(oldListName), true);
            
            SPList DestList = destWeb.Lists[OrigList.Title];

            SPView OrigView = OrigList.GetView(new Guid(oldViewGuid));
            SPView DestView = DestList.Views.Add(string.Empty, OrigView.ViewFields.ToStringCollection(), OrigView.Query,
                OrigView.RowLimit, OrigView.Paged, OrigView.DefaultView);
            DestView.Hidden = OrigView.Hidden;
            DestView.Scope = OrigView.Scope;
            DestView.ApplyStyle(destWeb.ViewStyles.StyleByID(Convert.ToInt32(OrigView.StyleID)));

            DestView.Update();

            newWebPart.ViewGuid = DestView.ID.ToString("B").ToUpper();
            newWebPart.ListName = destWeb.Lists[OrigList.Title].ID.ToString("B").ToUpper();


            return newWebPart;
        }
And against all odds it worked, I hope I don't have to deal with this webparts for a while.

No comments:

Post a Comment