Beispiel #1
0
        private void SimiasEventSyncCollectionHandler(SimiasEventArgs args)
        {
            try
            {
                if (args == null)
                {
                    Debug.PrintLine("SimiasEventSyncCollectionHandler received a null SimiasEventArgs");
                    return;
                }
                CollectionSyncEventArgs syncEventArgs =
                    args as CollectionSyncEventArgs;
                if (syncEventArgs == null || syncEventArgs.Name == null || syncEventArgs.ID == null)
                {
                    Debug.PrintLine("SimiasEventSyncCollectionHandler() Name, ID, Action, or Connected is null");
                    return;                     // Prevent a null object
                }

                if (ifdata.IsiFolder(syncEventArgs.ID))
                {
                    iFolderHolder ifHolder =
                        ifdata.GetiFolder(syncEventArgs.ID);

                    if (ifHolder != null)
                    {
                        switch (syncEventArgs.Action)
                        {
                        case Simias.Client.Event.Action.StartLocalSync:
                            ifHolder.State = iFolderState.SynchronizingLocal;
                            break;

                        case Simias.Client.Event.Action.StartSync:
                            ifHolder.State = iFolderState.Synchronizing;
                            break;

                        case Simias.Client.Event.Action.StopSync:
                            try
                            {
                                SyncSize syncSize = ifws.CalculateSyncSize(syncEventArgs.ID);
                                ifHolder.ObjectsToSync = syncSize.SyncNodeCount;
                            }
                            catch
                            {}

                            if (ifHolder.ObjectsToSync > 0)
                            {
                                ifHolder.State = iFolderState.Normal;
                            }
                            else
                            {
                                if (syncEventArgs.Connected || ifHolder.iFolder.Role == "Master")
                                {
                                    ifHolder.State = iFolderState.Normal;
                                }
                                else
                                {
                                    ifHolder.State = iFolderState.Disconnected;
                                }
                            }
                            break;
                        }

                        if ((ifHolder.iFolder.UnManagedPath == null) ||
                            (ifHolder.iFolder.UnManagedPath.Length == 0))
                        {
                            // Because the iFolder has no path
                            // re-read the iFolder and fire a changed event
                            ifHolder = ifdata.ReadiFolder(syncEventArgs.ID);
                            if (ifHolder != null)
                            {
                                lock (NodeEventQueue)
                                {
                                    NodeEventQueue.Enqueue(new SimiasEvent(
                                                               ifHolder.iFolder.ID, null,
                                                               null, SimiasEventType.ChangediFolder));
                                    SimiasEventFired.WakeupMain();
                                }
                            }
                        }
                    }
                }

                // pass the sync event on to the client
                lock (SyncEventQueue)
                {
                    SyncEventQueue.Enqueue(syncEventArgs);
                    SyncEventFired.WakeupMain();
                }
            }
            catch (Exception e)
            {
                if (printErrors)
                {
                    Debug.PrintLine("Exception in SimiasEventSyncCollectionHandler(): " + e.Message);
                    Debug.PrintLine(e.StackTrace);
                }
            }
        }
        /// <summary>
        /// Update iFolder
        /// </summary>
        /// <param name="ifolder">iFolderWeb Object</param>
        public void UpdateiFolder(iFolderWeb ifolder)
        {
            DomainController domainController = DomainController.GetDomainController();

            this.domain = domainController.GetDomain(ifolder.DomainID);

            this.ifolder = ifolder;

            if (ifolder.LastSyncTime == null || ifolder.LastSyncTime == "")
            {
                LastSuccessfulSync.Text = Util.GS("N/A");
            }
            else
            {
                LastSuccessfulSync.Text = ifolder.LastSyncTime;
            }
            FFSyncValue.Text = Util.GS("0");

            int syncInterval = 0;

            if (ifolder.EffectiveSyncInterval <= 0)
            {
                try
                {
                    syncInterval = ifws.GetDefaultSyncInterval();
                }
                catch
                {}
            }
            else
            {
                syncInterval = ifolder.EffectiveSyncInterval;
            }

            // Make sure it's shown in minutes
            if (syncInterval > 0)
            {
                syncInterval = syncInterval / 60;
            }

            SyncIntervalValue.Text = syncInterval + " " + Util.GS("minute(s)");

            string ifolderName = null, ifolderLocation = null;

            ifolderName     = ifolder.Name;
            ifolderLocation = ifolder.UnManagedPath;
            if (ifolder.Name.Length > displayName)
            {
                ifolderName = ifolder.Name.Substring(0, displayName) + "...";
            }
            if (ifolder.UnManagedPath.Length > displayableLocation)
            {
                ifolderLocation = ifolder.UnManagedPath.Substring(0, displayableLocation) + "...";
            }



            NameLabel.Markup     = string.Format("{0}", GLib.Markup.EscapeText(ifolderName));
            OwnerLabel.Markup    = string.Format("<span size=\"small\">{0}</span>", GLib.Markup.EscapeText(ifolder.Owner));
            LocationLabel.Markup = string.Format("<span size=\"small\">{0}</span>", GLib.Markup.EscapeText(ifolderLocation));
            AccountLabel.Markup  = string.Format("<span size=\"small\">{0}</span>", GLib.Markup.EscapeText(domain.Name));

            try
            {
                SyncSize ss = ifws.CalculateSyncSize(ifolder.ID);
                FFSyncValue.Text = string.Format("{0}", ss.SyncNodeCount);
            }
            catch (Exception)
            {
                FFSyncValue.Text = Util.GS("N/A");

//				iFolderExceptionDialog ied = new iFolderExceptionDialog(
//													topLevelWindow, e);
//				ied.Run();
//				ied.Hide();
//				ied.Destroy();
            }


            try
            {
                ds = ifws.GetiFolderDiskSpace(ifolder.ID);
            }
            catch (Exception)
            {
                ds = null;
//				iFolderExceptionDialog ied = new iFolderExceptionDialog(
//													topLevelWindow, e);
//				ied.Run();
//				ied.Hide();
//				ied.Destroy();
            }

            // check for iFolder Owner

/*			if(ifolder.CurrentUserID == ifolder.OwnerID)
 *                      {
 *                              if(LimitCheckButton == null)
 *                              {
 *                                      LimitCheckButton =
 *                                              new CheckButton(Util.GS("Set _Quota:"));
 *                                      LimitCheckButton.Toggled +=
 *                                                              new EventHandler(OnLimitSizeButton);
 *                                      diskTable.Attach(LimitCheckButton, 0,1,1,2,
 *                                              AttachOptions.Shrink | AttachOptions.Fill, 0,0,0);
 *
 *                                      LimitEntry = new Entry();
 *                                      LimitEntry.Changed +=
 *                                              new EventHandler(OnLimitChanged);
 *                                      LimitEntry.Activated +=
 *                                              new EventHandler(OnLimitEdited);
 *                                      LimitEntry.FocusOutEvent +=
 *                                              new FocusOutEventHandler(OnLimitFocusLost);
 *                                      LimitEntry.WidthChars = 6;
 *                                      LimitEntry.MaxLength = 10;
 *                                      LimitEntry.Layout.Alignment = Pango.Alignment.Left;
 *                                      diskTable.Attach(LimitEntry, 1,2,1,2,
 *                                              AttachOptions.Shrink | AttachOptions.Fill, 0,0,0);
 *                                      LimitCheckButton.ShowAll();
 *                                      LimitEntry.ShowAll();
 *                              }
 *                              else
 *                              {
 *                                      LimitCheckButton.Visible = true;
 *                                      LimitEntry.Visible = true;
 *                              }
 *
 *                              if(LimitLabel != null)
 *                              {
 *                                      LimitLabel.Visible = false;
 *                                      LimitValue.Visible = false;
 *                              }
 *                      }
 *                      else   */
//			{
            //Commenting the code since Owner of an iFolder canot change the quta settings set by the Admin . 261517
            if (LimitLabel == null)
            {
                LimitLabel        = new Label(Util.GS("Quota:"));
                LimitLabel.Xalign = 0;
                diskTable.Attach(LimitLabel, 0, 1, 0, 1,
                                 AttachOptions.Expand | AttachOptions.Fill, 0, 0, 0);

                LimitValue        = new Label(Util.GS("0"));
                LimitValue.Xalign = 1;
                diskTable.Attach(LimitValue, 1, 2, 0, 1,
                                 AttachOptions.Shrink | AttachOptions.Fill, 0, 0, 0);
                LimitLabel.ShowAll();
                LimitValue.ShowAll();
            }
            else
            {
                LimitLabel.Visible = true;
                LimitValue.Visible = true;
            }

            //LimitCheckButton never assinged, always has value NULL, below code will never get excuted

            /*
             * if(LimitCheckButton != null)
             * {
             *      LimitCheckButton.Visible = false;
             *      LimitEntry.Visible = false;
             * }*/
//			}

            if (ds != null)
            {
                int tmpValue;

                // there is no limit set, disable controls
                if (ds.Limit == -1)
                {
                    LimitUnit.Sensitive           = false;
                    AvailLabel.Sensitive          = false;
                    AvailValue.Sensitive          = false;
                    AvailUnit.Sensitive           = false;
                    DiskUsageBar.Sensitive        = false;
                    DiskUsageFrame.Sensitive      = false;
                    DiskUsageFullLabel.Sensitive  = false;
                    DiskUsageEmptyLabel.Sensitive = false;
                    AvailUnit.Text = "";
                    LimitUnit.Text = "";
                    //LimitCheckButton never assinged, always has value NULL, below code will never get excuted

                    /*	if(LimitCheckButton != null)
                     *      {
                     *              LimitCheckButton.Active = false;
                     *              LimitEntry.Sensitive = false;
                     *              LimitEntry.Text = Util.GS("0");
                     *      }*/
                    if (LimitLabel != null)
                    {
                        LimitLabel.Sensitive = false;
                        LimitValue.Sensitive = false;
                        LimitValue.Text      = Util.GS("N/A");
                    }
                    AvailValue.Text = Util.GS("N/A");
                }
                else
                {
                    LimitUnit.Sensitive           = true;
                    AvailLabel.Sensitive          = true;
                    AvailValue.Sensitive          = true;
                    AvailUnit.Sensitive           = true;
                    DiskUsageBar.Sensitive        = true;
                    DiskUsageFrame.Sensitive      = true;
                    DiskUsageFullLabel.Sensitive  = true;
                    DiskUsageEmptyLabel.Sensitive = true;
                    AvailUnit.Text = Util.GS("MB");
                    LimitUnit.Text = Util.GS("MB");

                    //LimitCheckButton never assinged, always has value NULL, below code will never get excuted

                    /*
                     * if(LimitCheckButton != null)
                     * {
                     *      LimitCheckButton.Active = true;
                     *      LimitEntry.Sensitive = true;
                     *      tmpValue = (int)(ds.Limit / (1024 * 1024));
                     *      LimitEntry.Text = string.Format("{0}", tmpValue);
                     * }*/
                    if (LimitLabel != null)
                    {
                        LimitLabel.Sensitive = true;
                        LimitValue.Sensitive = true;
                        tmpValue             = (int)(ds.Limit / (1024 * 1024));
                        LimitValue.Text      = string.Format("{0}", tmpValue);
                    }

                    tmpValue        = (int)(ds.AvailableSpace / (1024 * 1024));
                    AvailValue.Text = string.Format("{0}", tmpValue);
                }

                SetGraph(ds.UsedSpace, ds.Limit);

                // Add one because there is no iFolder that is zero
                if (ds.UsedSpace == 0)
                {
                    UsedValue.Text = Util.GS("0");
                }
                else
                {
                    tmpValue       = (int)(ds.UsedSpace / (1024 * 1024)) + 1;
                    UsedValue.Text = string.Format("{0}", tmpValue);
                }
            }
            SecureSync.Active = ifolder.ssl;
            // allow User to change the secure sync [ ssl ] if user is owner of iFolder
            if (ifolder.CurrentUserID != ifolder.OwnerID)
            {
                SecureSync.Sensitive = false;
            }

            if (domain.HostUrl.StartsWith(System.Uri.UriSchemeHttps))
            {
                SecureSync.Active    = true;
                SecureSync.Sensitive = false;
            }
        }